package com.example.project.controller.statistics;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.project.core.domain.AjaxResult;
import com.example.project.enums.ReportType;
import com.example.project.service.ProjectReportService;
import com.example.project.utils.DateUtils;
import com.example.project.vo.ProjectReportRequest;

/**
 * 报表导出测试Controller
 * 
 * @author ruoyi
 * @date 2025-10-24
 */
@RestController
@RequestMapping("/test/report")
public class ReportExportTestController {

    @Autowired
    private ProjectReportService projectReportService;
    
    /**
     * 测试报表数据查询
     */
    @GetMapping("/testData")
    public AjaxResult testReportData() {
		try {
			// 创建测试请求
			ProjectReportRequest request = new ProjectReportRequest();
			request.setStartDate(DateUtils.dateTime(new Date(System.currentTimeMillis() - 30L * 24 * 60 * 60 * 1000))); // 30天前
			request.setEndDate(DateUtils.getDate()); // 当前时间
			request.setReportType(ReportType.PROJECT_BASIC_INFO);

            // 测试各种报表类型的数据查询
            System.out.println("=== 测试项目基本信息报表 ===");
            var basicInfo = projectReportService.getProjectBasicInfoData(request);
            System.out.println("项目基本信息数据条数: " + basicInfo.size());
            
            request.setReportType(ReportType.PROJECT_STATISTICS);
            System.out.println("=== 测试项目统计报表 ===");
            var statistics = projectReportService.getProjectStatisticsData(request);
            System.out.println("项目统计数据条数: " + statistics.size());
            
            request.setReportType(ReportType.ISSUE_DETAIL_REPORT);
            System.out.println("=== 测试问题明细报表 ===");
            var issueDetail = projectReportService.getIssueDetailData(request);
            System.out.println("问题明细数据条数: " + issueDetail.size());
            
            request.setReportType(ReportType.CUSTOMER_PROJECT_REPORT);
            System.out.println("=== 测试客户项目关系报表 ===");
            var customerProject = projectReportService.getCustomerProjectData(request);
            System.out.println("客户项目关系数据条数: " + customerProject.size());
            
            request.setReportType(ReportType.COMPREHENSIVE_REPORT);
            System.out.println("=== 测试综合项目分析报表 ===");
            var comprehensive = projectReportService.getComprehensiveAnalysisData(request);
            System.out.println("综合项目分析数据条数: " + comprehensive.size());
            
            return AjaxResult.success("报表数据查询测试完成，请查看控制台输出");
            
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("报表数据查询测试失败: " + e.getMessage());
        }
    }
}